import java.util.*;

public class BinaryConverter {
    private static final Scanner scanner;
    private static boolean flagMain;
    private static String g;
    static {
        scanner = new Scanner(System.in);
        flagMain = false;
    }
    private static String getFirstNumber(String s) {
        StringBuilder sb = new StringBuilder();
        boolean isDotted = false;
        int v = 0;
        sb.append(s.charAt(0));
        for (int i = 1; i < s.length(); i++) {
            char c = s.charAt(i);
            if (Character.isDigit(c)) {
                sb.append(c);
                v++;
            } else if ((c == '.' || c == ',') && !isDotted) {
                sb.append(c);
                isDotted = true;
            } else {
                if (sb.charAt(sb.length() - 1) == '.' || sb.charAt(sb.length() - 1) == ',') {
                    sb.deleteCharAt(sb.length() - 1);
                }
                break;
            }
        }
        if (v > 0)
            return sb.toString();
        else return "0";
    }
    private static String convertByte(String n) {
        StringBuilder sb = new StringBuilder();
        byte b = Byte.parseByte(n);
        for (int i = 7; i >= 0; --i) {
            sb.append(b >>> i & 1);
        }
        return sb.toString();
        //return Integer.toBinaryString(b);
    }
    private static String convertShort(String n) {
        StringBuilder sb = new StringBuilder();
        short t = Short.parseShort(n);
        for (int i = 15; i >= 0; --i) {
            sb.append(t >>> i & 1);
        }
        return sb.toString();
        //return Integer.toBinaryString(t);
    }
    private static String convertInt(String n) {
        StringBuilder sb = new StringBuilder();
        int h = Integer.parseInt(n);
        for (int i = 31; i >= 0; --i) {
            sb.append(h >>> i & 1);
        }
        return sb.toString();
        //return Integer.toBinaryString(i);
    }
    private static String convertLong(String n) {
        StringBuilder sb = new StringBuilder();
        long l = Long.parseLong(n);
        for (int i = 63; i >= 0; --i) {
            sb.append(l >>> i & 1);
        }
        return sb.toString();
        //return Long.toBinaryString(l);
    }
    private static String convertFloat(float n) throws NumberFormatException {
        long lbits = Float.floatToIntBits(n);
        long lsign = lbits >>> 31;
        long lexp = (lbits >>> 23 & ((1 << 8) - 1)) - ((1 << 10) - 1);
        long lmantissa = lbits & ((1 << 23) - 1);
        return lsign + " " + lexp + " " + lmantissa;
        //return Integer.toBinaryString(Float.floatToRawIntBits(n));
    }
    private static String convertDouble(double n) throws NumberFormatException {
        long lbits = Double.doubleToLongBits(n);
        long lsign = lbits >>> 63;
        long lexp = (lbits >>> 52 & ((1 << 11) - 1)) - ((1 << 10) - 1);
        long lmantissa = lbits & ((1L << 52) - 1);
        return lsign + " " +  lexp + " " + lmantissa;
        //return Long.toBinaryString(Double.doubleToRawLongBits(n));
    }
    private static double readDouble(String n) throws NumberFormatException {
        n = n.replaceAll(",", ".");
        return Double.parseDouble(n);
    }
    private static float readFloat(String n) throws NumberFormatException {
        n = n.replaceAll(",", ".");
        return Float.parseFloat(n);
    }
    private static void menu(String n) {
        String[] m = {"byte", "short", "int", "long", "float", "double"};
        List<String> list = new ArrayList<>(Arrays.asList(m));
        double t = readDouble(n);
        if (t % 1 != 0.0) {
            list.remove("byte");
            list.remove("short");
            list.remove("int");
            list.remove("long");
        }
        if (t < Byte.MIN_VALUE || t > Byte.MAX_VALUE)
            list.remove("byte");
        if (t < Short.MIN_VALUE || t > Short.MAX_VALUE)
            list.remove("short");
        if (t < Integer.MIN_VALUE || t > Integer.MAX_VALUE)
            list.remove("int");
        if (t < Long.MIN_VALUE || t > Long.MAX_VALUE)
            list.remove("long");
        System.out.println("Input one of the types below and press Enter:");
        for (String i: list) {
            System.out.println(i);
        }
        g = n;
        contain(list);
    }
    private static void contain(List l) {
        String n = scanner.next();
        if (l.contains(n))
            submenu(n);
        else {
            System.out.println("Try again.");
            contain(l);
        }
    }
    private static void submenu(String b) {
        switch (b) {
            case "double" -> System.out.println(convertDouble(readDouble(g)));
            case "float" -> System.out.println(convertFloat(readFloat(g)));
            case "long" -> System.out.println(convertLong(g));
            case "int" -> System.out.println(convertInt(g));
            case "short" -> System.out.println(convertShort(g));
            case "byte" -> System.out.println(convertByte(g));
            default -> {
                System.out.println("Just type one of types above. Try again.");
                menu(getFirstNumber(g));
            }
        }
    }
    public static void main(String[] args) throws NumberFormatException {
        while (!flagMain) {
            System.out.println("Input your number or type \"quit\" and press Enter:");
            String u = scanner.next();
            if (u.equals("quit")) {
                flagMain = true;
            } else {
                menu(getFirstNumber(u));
            }
        }
    }
}
